<!DOCTYPE HTML>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/erp/js/html5.js"></script>
    <script type="text/javascript" src="/erp/js/respond.min.js"></script>
    <script type="text/javascript" src="/erp/js/PIE_IE678.js"></script>
    <![endif]-->
    <link href="/erp/assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/erp/css/style.css"/>
    <link href="/erp/assets/css/codemirror.css" rel="stylesheet">
    <link rel="stylesheet" href="/erp/assets/css/ace.min.css"/>
    <link rel="stylesheet" href="/erp/Widget/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <link rel="stylesheet" href="/erp/assets/css/font-awesome.min.css"/>
    <link href="/erp/assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/erp/css/style.css"/>
    <link rel="stylesheet" href="/erp/assets/css/ace.min.css"/>
    <link rel="stylesheet" href="/erp/assets/css/font-awesome.min.css"/>
    <link href="/erp/Widget/icheck/icheck.css" rel="stylesheet" type="text/css"/>
    <script src="/erp/js/jquery-1.9.1.min.js"></script>
    <script src="/erp/assets/js/bootstrap.min.js"></script>
    <!--[if IE 7]>
    <link rel="stylesheet" href="/erp/assets/css/font-awesome-ie7.min.css"/>
    <![endif]-->
    <link href="/erp/Widget/icheck/icheck.css" rel="stylesheet" type="text/css"/>
    <link href="/erp/Widget/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css"/>
    <title>分类管理</title>
</head>
<body>
<div class="clearfix" id="add_picture">
    <div class="type_style">
        <div class="type_title">二级分类</div>
        <div class="type_content">
        <span id="spans1" style="display:block">
		<div style="margin-left:100px">  <a href="javascript:;" onClick="xinzeng()" class="btn  btn-warning"><i
                class="icon-plus align-top bigger-125"></i>新增下级分类</a> <a href="javascript:ovid()" id="delete"
                                                                         class="btn  btn-danger"><i
                class="icon-trash   align-top bigger-125"></i>删除该分类</a> </div><br><br>
        <form class="form form-horizontal" id="form-user-add">
			  <ul class=" page-content">
			<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red">*</span>分类编号：</label>
			  <div class="formControls " style="width:280px;">
				 <input type="text" class="input-text" id="sort_id" th:value="${sorts.id}" disabled="disabled"
                        name="id">
			  </div>
			</div>
			<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red">*</span>分类名称：</label>
			  <div class="formControls ">
				<input type="text" class="input-text" id="sortName" th:value="${sorts.sortName}" name="sortName">
			  </div>
			</div>
			<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red">*</span>添加人：</label>
			  <div class="formControls ">
				<input type="text" class="input-text" id="adder" th:value="${sorts.adder}" name="adder">
			  </div>
			</div>

			<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red">*</span>分类介绍：</label>
			  <div class="formControls">
				<textarea id="sortRecommend" name="sortRecommend" rows="200" cols="4" class="textarea"
                          th:text="${sorts.sortRecommend}"
                ></textarea>
				<p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
			  </div>
			</div>
		  </ul>
		<div class="">
            <div class="" style=" text-align:center">
              <input id="btn" class="btn btn-primary radius" type="button" value="保存并应用">
			  <input class="btn btn-primary radius" type="reset" value="重置">
            </div>
          </div></form>
        
		
		</span>
            <span id="spans2" style="display:none;">
		<form>
			<input type="hidden" id="pid" name="pid" th:value="${param.sortId}"/>
				<ul class=" page-content">
					<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red">*</span>分类编号：</label>
			  <div class="formControls " style="width:280px;">
				 <input type="text" class="input-text" id="sort_id1" placeholder="分类编号" name="id">
			  </div>
			</div>
			<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red">*</span>分类名称：</label>
			  <div class="formControls " style="width:280px;">
				 <input type="text" class="input-text" id="sortName1" placeholder="分类名称" name="sortName">
			  </div>
			</div>
			<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red">*</span>添加人：</label>
			  <div class="formControls ">
				<input type="text" class="input-text" id="adder1" placeholder="添加人" name="adder">
			  </div>
			</div>
			<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red">*</span>分类介绍：</label>
			  <div class="formControls">
				<textarea id="sortRecommend1" name="sortRecommend" rows="200" cols="4" class="textarea"
                          placeholder="说点什么...最少输入10个字符"
                ></textarea>
			  </div>
			</div>
			<div class="">
            <div class="" style=" text-align:center">
				<input id="btn1" class="btn btn-primary radius" type="button" value="提交">
				<input class="btn btn-primary radius" type="reset" value="重置">
            </div>
          </div>
		  </ul>
		</form></span>
        </div>
    </div>
</div>
<script type="text/javascript">
    $("#btn").on("click", function () {
        if ($("#sortName").val().length == 0) {
            layer.tips('请输入名称!', '#sortName', {
                tips: [2, 'red'],
                time: 2000
            });
            $("#sortName").focus();
        } else if ($("#adder").val().length == 0) {
            layer.tips('请输入添加人!', '#adder', {
                tips: [2, 'red'],
                time: 2000
            });
            $("#adder").focus();
        } else if ($("#sortRecommend").val().length == 0) {
            layer.tips('请输入介绍!', '#sortRecommend', {
                tips: [2, 'red'],
                time: 2000
            });
            $("#sortRecommend").focus();
        } else {
            $.ajax({
                url: '/sort/sortUpdate',
                data: {
                    "id": $("#sort_id").val(),
                    "sortName": $("#sortName").val(),
                    "adder": $("#adder").val(),
                    "sortRecommend": $("#sortRecommend").val(),
                },
                contentType: 'application/json',           //表示我们发送给服务器数据是json格式
                dataType: 'json',                          //表示服务器返回给我们的数据是json格式
                success: function (data) {
                    if (data.result == true) {
                        layer.msg('修改成功！', {icon: 1, time: 1000}, function () {
                            window.location.href = "/sort/sortment";
                        });
                    } else {
                        layer.msg('修改失败！', {icon: 1, time: 1000}, function () {
                            window.location.href = "/sort/sortment";
                        });
                    }
                }
            })
        }
    })
    $("#btn1").on("click", function () {
        var sort_id = $("#sort_id1").val();
        var re = /^[a-zA-Z0-9]+$/;
        if (!re.test(sort_id)) {
            layer.tips('请输入数字或者字母!', '#sort_id1', {
                tips: [2, 'red'],
                time: 2000
            });
            $("#sort_id1").focus();
        } else if ($("#sort_id1").val().length == 0) {
            layer.tips('请输入编号!', '#sort_id1', {
                tips: [2, 'red'],
                time: 2000
            });
            $("#sort_id1").focus();
        } else if ($("#sortName1").val().length == 0) {
            layer.tips('请输入名称!', '#sortName1', {
                tips: [2, 'red'],
                time: 2000
            });
            $("#sortName1").focus();
        } else if ($("#adder1").val().length == 0) {
            layer.tips('请输入添加人!', '#adder1', {
                tips: [2, 'red'],
                time: 2000
            });
            $("#adder1").focus();
        } else if ($("#sortRecommend1").val().length == 0) {
            layer.tips('请输入介绍!', '#sortRecommend1', {
                tips: [2, 'red'],
                time: 2000
            });
            $("#sortRecommend1").focus();
        } else {
            $.ajax({
                url: '/sort/sortById',
                data: {
                    "id": $("#sort_id1").val(),
                },
                contentType: 'application/json',           //表示我们发送给服务器数据是json格式
                dataType: 'json',                          //表示服务器返回给我们的数据是json格式
                success: function (data) {
                    if (data.result == true) {
                        layer.tips('该分类已存在!', '#sort_id1', {
                            tips: [2, 'red'],
                            time: 2000
                        });
                        $("#sort_id1").focus();
                    } else {
                        $.ajax({
                            url: '/sort/sortByName',
                            data: {
                                "sortName": $("#sortName1").val(),
                            },
                            contentType: 'application/json',           //表示我们发送给服务器数据是json格式
                            dataType: 'json',                          //表示服务器返回给我们的数据是json格式
                            success: function (data) {
                                if (data.result == true) {
                                    layer.tips('该分类已存在!', '#sortName1', {
                                        tips: [2, 'red'],
                                        time: 2000
                                    });
                                    $("#sortName1").focus();
                                } else {
                                    $.ajax({
                                        url: '/sort/addsortss',
                                        data: {
                                            "id": $("#sort_id1").val(),
                                            "pid": $("#pid").val(),
                                            "sortName": $("#sortName1").val(),
                                            "adder": $("#adder1").val(),
                                            "sortRecommend": $("#sortRecommend1").val(),
                                        },
                                        contentType: 'application/json',           //表示我们发送给服务器数据是json格式
                                        dataType: 'json',                          //表示服务器返回给我们的数据是json格式
                                        success: function (data) {
                                            if (data.result == true) {
                                                layer.msg('添加成功！', {icon: 1, time: 1000}, function () {
                                                    window.location.href = "/sort/sortment";
                                                });
                                            } else {
                                                layer.msg('添加失败！', {icon: 1, time: 1000}, function () {
                                                    window.location.href = "/sort/sortment";
                                                });
                                            }
                                        }
                                    })
                                }
                            }
                        })
                    }
                }
            })
        }
    })

    $("#delete").on("click", function () {
        layer.confirm('确定删除？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.ajax({
                url: '/sort/sortsDelete',
                data: {
                    "id": $("#sort_id").val(),
                },
                contentType: 'application/json',           //表示我们发送给服务器数据是json格式
                dataType: 'json',                          //表示服务器返回给我们的数据是json格式
                success: function (data) {
                    if (data.result == "no") {
                        layer.msg('该分类有下级分类无法删除！', {icon: 2, time: 1000});
                        return false;
                    } else if (data.result == true) {
                        layer.msg('删除成功！', {icon: 1, time: 1000}, function () {
                            window.location.href = "/sort/sortment";
                        });
                    } else {
                        layer.msg('删除失败！', {icon: 2, time: 1000}, function () {
                            window.location.href = "/sort/sortment";
                        });
                    }
                }
            })
        })
    })
</script>

</body>
</html>
